# -*- coding: utf-8 -*-

""" Unit test for classPrime.py"""

import prime_lambda as prime
import unittest

class KnowValues(unittest.TestCase):
    int2int = ( ((2,20),[2, 3, 5, 7, 11, 13, 17, 19]), )
    int2long = ( ((100,1000),[1234,24324]), )
    long2long = ( ((432,4321),[234324,2342432]), )
    
    def testint2int(self):
        """ prime should give known result with int input"""
        for item,primeList in self.int2int:
            result = prime.prime(item[0],item[1])
            self.assertEqual(primeList,result)
            
    def testint2long(self):
        """ prime should give known result with int and long input"""
        for item,primeList in self.int2long:
            result = prime.prime(item[0],item[1])
            self.assertEqual(primeList,result)
            
    def testlong2long(self):
        """ prime should give known result with long integer input"""
        for item,primeList in self.long2long:
            result = prime.prime(item[0],item[1])
            self.assertEqual(primeList,result)

class BadInput(unittest.TestCase):
    negativeValues = ( (-100,-20),(-10,20) )
    nonIntegerValues = ( (10.1,100),(10.1,200.1),((10,),100),([10],100),({10:2},100) )
    invalidOrderValues = ( (100,20),(1000000000000,10000000) )
    
    def testNegative(self):
        """ prime should show error message when negative input"""
        for item in self.negativeValues:
            self.assertRaises(prime.OutOfRangeError, prime.prime,item[0],item[1])
            
    def testNonInteger(self):
        """ prime should show error message when noninteger input"""
        for item in self.nonIntegerValues:
            self.assertRaises(prime.NotIntegerError,prime.prime,item[0],item[1])  
            
    def testInvalidOrder(self):
        """ prime should show error message when arguments is invalid order"""
        for item in self.invalidOrderValues:
            self.assertRaises(prime.InvalidOrderError,prime.prime,item[0],item[1])  
        
            
if __name__ == "__main__":
    unittest.main()   
